const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
module.exports = {
  //  入口文件
  entry: './src/main.ts',
  // 出口文件
  output: {
    //打包目录
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  mode: 'development', // 设置mode
  // 打包时需要的模块
  module: {
    // 指定加载规则
    rules: [
      {
        test: /\.ts$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: [
                [
                  '@babel/preset-env',
                  {
                    targets: {
                      // 兼容版本
                      "ie": "11"
                    },
                    "corejs": "3",
                    //按需加载corejs
                    "useBuiltIns": "usage"
                  }
                ]
              ]
            }
          }
          ,'ts-loader'],
        exclude: /node_modules/
      },
      {
        test: /\.(less|css)$/,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "postcss-loader",
            options: {
              postcssOptions: {
                plugins: [
                  [
                    "postcss-preset-env",
                    {
                      browsers: 'last 2 versions'
                    }
                  ]
                ]
              }
            }
          },
          "less-loader"
        ]
      },
      {
        test: /\.(eot | woff2 |woff |ttf|svf)$/,
        use:['file-loader']
      }
    ]
  },
  plugins: [
    new HTMLWebpackPlugin({
      template: './src/index.html'
    })
  ],
  resolve: {
    extensions: ['.ts', '.js']
  }
}